home *** CD-ROM | disk | FTP | other *** search
/ Software 2000 / Software 2000 Volume 1 (Disc 1 of 2).iso / education / e077.dms / e077.adf / ScienceDemos / SIDEREAL (.txt) < prev    next >
AmigaBASIC Source Code  |  1991-07-12  |  12KB  |  401 lines

  1. ' Program "SIDEREAL"
  2.  
  3. ' Copyright (C) 1986 by David Eagle
  4. ' 7952 W. Quarto Dr., Littleton, CO 80123, (303) 972-4020
  5. ' released into the public domain on March 30, 1986
  6.  
  7. DEFDBL a-z
  8. DIM SHARED month$(12)
  9.  
  10. SCREEN 1,640,200,3,2
  11. WINDOW 5,"Program SIDEREAL",(0,0)-(630,185),0,1
  12. PALETTE 4,0,0.8,0.2:' green
  13. PALETTE 5,1,1,0:' yellow
  14. PALETTE 6,0.8,0,0.93:' purple
  15. PALETTE 7,0.93,0.2,0:' red
  16.  
  17. pi=5.30795e-315
  18. pi2=2*pi
  19. deg.to.rad=pi/180
  20. we=5.28971e-315
  21. xe=pi/12
  22. xer=12/pi
  23.  
  24. month$(1)="January"
  25. month$(2)="February"
  26. month$(3)="March"
  27. month$(4)="April"
  28. month$(5)="May"
  29. month$(6)="June"
  30. month$(7)="July"
  31. month$(8)="August"
  32. month$(9)="September"
  33. month$(10)="October"
  34. month$(11)="November"
  35. month$(12)="December"
  36.  
  37. DEF FNjdate0(month%,day%,year%)=367*year%-INT(7*((year%+INT((month%+9)/12))/4))+INT(275*month%/9)+day%+5.40674e-315-INT(3*(INT((year%+SGN(month%-9)*INT(ABS((month%-9)/7)))/100)+1)/4)
  38. DEF FNgmtime(h,m,s,tz%,dst%)=h+m/60+s/3600+tz%-dst%
  39. DEF FNdemod(x)=x-pi2*INT(x/pi2)
  40.  
  41. ' initialization
  42. CLS
  43. select%=1
  44.  
  45. CALL yesno.menu("Program introduction ?",intro%)
  46. IF intro%=1 THEN CALL introduction
  47. CLS
  48.  
  49. WHILE select%=1
  50.  
  51.  CALL selection.menu(choice%)
  52.  
  53.  IF choice%=1 THEN CALL jdate.from.gdate
  54.  IF choice%=2 THEN CALL gdate.from.jdate
  55.  IF choice%=3 THEN CALL lst.from.lct
  56.  IF choice%=4 THEN CALL lct.from.lst
  57.  
  58.  CALL display.data(choice%)
  59.  CALL yesno.menu("Another selection ?",select%)
  60.   
  61. WEND
  62. WINDOW CLOSE 5
  63. SCREEN CLOSE 1
  64. END
  65.  
  66. SUB lct.from.lst STATIC
  67. ' local civil time from local sidereal time subroutine
  68. SHARED xe,xer,we,deg.to.rad,jdate,cdate$,wlong$,lct$,lst$,time.zone%,dst.flag%
  69. CLS
  70. PRINT
  71. COLOR 3,0
  72. PRINT "Calendar date ( month <1-12>, day <1-31>, year <YYYY> )"
  73. PRINT "< NOTE: B.C. dates are negative, A.D. dates are positive >"
  74. PRINT "< For example, October 21, 1948 is input as 10,21,1948 >"
  75. INPUT month%,day%,year%
  76. cdate$=month$(month%)+STR$(day%)+","+STR$(year%)
  77. PRINT
  78. COLOR 4,0
  79. PRINT "Local sidereal time (hour <0-23>, minute <0-59), second <0-59>)"
  80. INPUT lst.hr,lst.min,lst.sec
  81. lst$=STR$(lst.hr)+" hours"+STR$(lst.min)+" minutes"+STR$(lst.sec)+" seconds"
  82. PRINT
  83. COLOR 5,0
  84. PRINT "West longitude (degree <0-359>, minute <0-59>, second <0-59>)"
  85. INPUT wlong.deg,wlong.min,wlong.sec
  86. wlong.rad=deg.to.rad*(wlong.deg+wlong.min/60+wlong.sec/3600)
  87. wlong$=STR$(wlong.deg)+ " degrees"+STR$(wlong.min)+" minutes"+STR$(wlong.sec)+" seconds"
  88. PRINT
  89. COLOR 6,0
  90. PRINT "Time zone ( 0-23 )"
  91. PRINT "< For example, Eastern Standard Time (EST) is time zone 5 >"
  92. INPUT time.zone%
  93. PRINT
  94. COLOR 7,0
  95. PRINT "Daylight Savings Time ( y = yes, n = no )"
  96. INPUT dst$
  97. IF dst$="y" THEN dst.flag%=1 :ELSE dst.flag%=0
  98. jd0=FNjdate0(month%,day%,year%)
  99. t2=(jd0-2451545)/36525
  100. lst=FNdemod(5.30371e-315+5.34761e-315*t2+6.7707e-06*t2^2)
  101. t1=xe*(lst.hr+lst.min/60+lst.sec/3600)
  102. IF ABS(lst-t1)<0.001 THEN
  103.  t2=(jd0-2451544)/36525
  104.  lst=FNdemod(5.30371e-315+5.34761e-315*t2+6.7707e-06*t2^2)
  105.  t1=xe*(lst.hr+lst.min/60+lst.sec/3600)
  106. END IF
  107. a=(t1-lst+wlong.rad)/we-time.zone%+dst.flag%
  108. a=a-24*INT(a/24)
  109. CALL convert(a,lct.hr,lct.min,lct.sec)
  110. lct$=STR$(lct.hr)+" hours"+STR$(lct.min)+" minutes"+STR$(lct.sec)+" seconds"
  111. jdate=jd0+(lct.hr+lct.min/60+lct.sec/3600+time.zone%-dst.flag%)/24
  112. END SUB
  113.  
  114. SUB jdate.from.gdate STATIC
  115. ' julian date from calendar date subroutine
  116. SHARED time.zone%,dst.flag%,lct$,lst$,cdate$,jdate
  117. CLS
  118. PRINT
  119. COLOR 3,0
  120. PRINT "Calendar date ( month <1-12>, day <1-31>, year <YYYY> )"
  121. PRINT "< NOTE: B.C. dates are negative, A.D. dates are positive >"
  122. PRINT "< For example, October 21, 1948 is input as 10,21,1948 >"
  123. INPUT month%,day%,year%
  124. cdate$=month$(month%)+STR$(day%)+","+STR$(year%)
  125. PRINT
  126. COLOR 4,0
  127. PRINT "Local civil time (hour <0-23>, minute <0-59), second <0-59>)"
  128. PRINT "< For example, 8:30:45 p.m. is input as 20,30,45 >"
  129. INPUT lct.hr,lct.min,lct.sec
  130. lct$=STR$(lct.hr)+" hour"+STR$(lct.min)+" minutes"+STR$(lct.sec)+" seconds"
  131. PRINT
  132. COLOR 5,0
  133. PRINT "Time zone ( 0-23 )"
  134. PRINT "< For example, Eastern Standard Time (EST) is time zone 5 >"
  135. INPUT time.zone%
  136. PRINT
  137. COLOR 6,0
  138. PRINT "Daylight Savings Time ( y = yes, n = no )"
  139. INPUT dst$
  140. IF dst$="y" THEN dst.flag%=1 :ELSE dst.flag%=0
  141. jd0=FNjdate0(month%,day%,year%)
  142. gmt.time=FNgmtime(lct.hr,lct.min,lct.sec,time.zone%,dst.flag%)
  143. jdate=jd0+gmt.time/24
  144. END SUB
  145.  
  146. SUB lst.from.lct STATIC
  147. ' local sidereal time from local civil time subroutine
  148. SHARED time.zone%,dst.flag%
  149. SHARED xer,we,deg.to.rad,lst$,cdate$,lct$,wlong$,jdate
  150. CLS
  151. PRINT
  152. COLOR 3,0
  153. PRINT "Calendar date ( month <1-12>, day <1-31>, year <YYYY> )"
  154. PRINT "< NOTE: B.C. dates are negative, A.D. dates are positive >"
  155. PRINT "< For example, October 21, 1948 is input as 10,21,1948 >"
  156. INPUT month%,day%,year%
  157. cdate$=month$(month%)+STR$(day%)+","+STR$(year%)
  158. PRINT
  159. COLOR 4,0
  160. PRINT "Local civil time (hour <0-23>, minute <0-59), second <0-59>)"
  161. PRINT "< For example, 8:30:45 p.m. is input as 20,30,45 >"
  162. INPUT lct.hr,lct.min,lct.sec
  163. lct$=STR$(lct.hr)+" hours"+STR$(lct.min)+" minutes"+STR$(lct.sec)+" seconds"
  164. PRINT
  165. COLOR 5,0
  166. PRINT "West longitude (degree <0-359), minute <0-59>, second <0-59>)"
  167. INPUT wlong.deg,wlong.min,wlong.sec
  168. wlong.rad=deg.to.rad*(wlong.deg+wlong.min/60+wlong.sec/3600)
  169. wlong$=STR$(wlong.deg)+ " degrees"+STR$(wlong.min)+" minutes"+STR$(wlong.sec)+" seconds"
  170. PRINT
  171. COLOR 6,0
  172. PRINT "Time zone ( 0-23 )"
  173. PRINT "< For example, Eastern Standard Time (EST) is time zone 5 >"
  174. INPUT time.zone%
  175. PRINT
  176. COLOR 7,0
  177. PRINT "Daylight Savings Time ( y = yes, n = no )"
  178. INPUT dst$
  179. IF dst$="y" THEN dst.flag%=1 :ELSE dst.flag%=0
  180. jd0=FNjdate0(month%,day%,year%)
  181. gmt.time=FNgmtime(lct.hr,lct.min,lct.sec,time.zone%,dst.flag%)
  182. jdate=jd0+gmt.time/24
  183. t2=(jd0-2451545)/36525
  184. lst=FNdemod(5.30371e-315+5.34761e-315*t2+6.7707e-06*t2^2-wlong.rad+we*gmt.time)
  185. CALL convert(lst*xer,lst.hr,lst.min,lst.sec)
  186. lst$=STR$(lst.hr)+" hours"+STR$(lst.min)+" minutes"+STR$(lst.sec)+" seconds"
  187. END SUB
  188.  
  189. SUB convert(deg,hr,min,sec) STATIC
  190. ' convert angular time to hms subroutine
  191. hr=INT(deg)
  192. c=60*(deg-hr)
  193. min=INT(c)
  194. sec=INT(60*(c-min)+0.5)
  195. IF sec>=60 THEN
  196.  min=min+1
  197.  sec=sec-60
  198. END IF
  199. IF min>=60 THEN
  200.  hr=hr+1
  201.  min=min-60
  202. END IF
  203. IF hr>=24 THEN hr=hr-24
  204. END SUB  
  205.  
  206. SUB gdate.from.jdate STATIC
  207. ' Gregorian Date from Julian Date subroutine
  208. SHARED jdate,cdate$,lct$
  209. CLS
  210. PRINT
  211. COLOR 3,0
  212. PRINT "Julian Date"
  213. INPUT jdate
  214. z=INT(jdate+0.5)
  215. f=jdate+0.5-z
  216. IF z<2299161 THEN
  217.  a=z
  218. ELSE 
  219.  a=INT((z-5.40747e-315)/36524.2)
  220.  a=z+a-INT(a/4)+1
  221. END IF
  222. b=a+1524
  223. c=INT((b-122.1)/365.25)
  224. d=INT(365.25*c)
  225. e=INT((b-d)/30.6001)
  226. day%=b-d-INT(30.6001*e)
  227. IF e<13.5 THEN month%=e-1 :ELSE month%=e-13
  228. IF month%>2.5 THEN year%=c-4716 :ELSE year%=c-4715
  229. cdate$=month$(month%)+STR$(day%)+","+STR$(year%)
  230. CALL convert(24*f,lct.hr,lct.min,lct.sec)
  231. lct$=STR$(lct.hr)+" hours"+STR$(lct.min)+" minutes"+STR$(lct.sec)+" seconds"
  232. END SUB
  233.  
  234. SUB display.data(choice%) STATIC
  235. ' display data subroutine
  236. SHARED jdate,cdate$,lct$,lst$,time.zone%,dst.flag%,wlong$
  237. WINDOW 3,"SIDEREAL Data                (press left mouse button to continue)",(0,0)-(630,185),0,1
  238. CLS
  239. PRINT
  240. PRINT
  241. COLOR 1,0
  242. PRINT TAB(5);"Calendar date";TAB(60-LEN(cdate$));cdate$
  243. PRINT
  244. COLOR 2,0
  245. PRINT TAB(5);"Julian Date";
  246. LOCATE ,47
  247. PRINT USING "########.####";jdate
  248. PRINT
  249. COLOR 3,0
  250. PRINT TAB(5);"Local civil time";TAB(60-LEN(lct$));lct$
  251. IF choice%=3 OR choice%=4 THEN
  252.  PRINT
  253.  COLOR 4,0
  254.  PRINT TAB(5);"Local sidereal time";TAB(60-LEN(lst$));lst$
  255.  PRINT
  256.  COLOR 5,0
  257.  PRINT TAB(5);"West longitude";TAB(60-LEN(wlong$));wlong$
  258. END IF
  259. PRINT
  260. COLOR 6,0
  261. PRINT TAB(5);"Time Zone";TAB(45);time.zone%
  262. PRINT
  263. COLOR 7,0
  264. IF dst.flag%=1 THEN dst$="Yes" :ELSE dst$="No"
  265. PRINT TAB(5);"Daylight Savings Time";TAB(46);dst$
  266. WHILE MOUSE(0)=0:WEND
  267. WHILE MOUSE(0)<>0:WEND
  268. WINDOW CLOSE 3
  269. END SUB
  270.  
  271. SUB yesno.menu(request$,response%) STATIC
  272. ' yes/no request subroutine
  273. WINDOW 3,request$,(0,0)-(215,45),0,1
  274. LOCATE 1,1:PRINT PTAB(25);"press left mouse"
  275. LOCATE 2,1:PRINT PTAB(25);"button to select"
  276. LINE (20,20)-(80,40),1,b
  277. LINE (140,20)-(190,40),1,b
  278. LOCATE 4,1:PRINT PTAB(35);"Yes";PTAB(155);"No";
  279. response%=-1 
  280. WHILE response%=-1
  281.  WHILE MOUSE(0)=0:WEND
  282.  mx=MOUSE(1):my=MOUSE(2)
  283.  IF (mx>20 AND mx<80) AND (my>20 AND my<40) THEN
  284.   response%=1
  285.   WHILE MOUSE(0)<>0:WEND
  286.  END IF 
  287.  IF (mx>140 AND mx<190) AND (my>20 AND my<40) THEN
  288.   response%=2
  289.   WHILE MOUSE(0)<>0:WEND
  290.  END IF
  291. WEND
  292. WINDOW CLOSE 3
  293. END SUB
  294.  
  295. SUB selection.menu(selection%) STATIC
  296. ' selection menu subroutine
  297. WINDOW 3,"Sidereal Menu",(0,0)-(480,140),0,1
  298. LOCATE 1,1:PRINT PTAB(40);"please press left mouse button to select"
  299. LINE (20,20)-(450,40),1,b
  300. LINE (20,48)-(450,68),1,b
  301. LINE (20,74)-(450,94),1,b
  302. LINE (20,102)-(450,122),1,b
  303. LOCATE 4,1
  304. PRINT PTAB(30);"Julian Date from calendar date"
  305. LOCATE 7,1
  306. PRINT PTAB(30);"Calendar date from Julian Date"
  307. LOCATE 10,1
  308. PRINT PTAB(30);"Local sidereal time from local civil time"
  309. LOCATE 13,1
  310. PRINT PTAB(30);"Local civil time from local sidereal time"
  311. selection%=-1 
  312. WHILE selection%=-1
  313.  WHILE MOUSE(0)=0:WEND
  314.  mx=MOUSE(1):my=MOUSE(2)
  315.  IF (mx>20 AND mx<450) AND (my>20 AND my<40) THEN
  316.   selection%=1
  317.   WHILE MOUSE(0)<>0:WEND
  318.  END IF 
  319.  IF (mx>20 AND mx<450) AND (my>48 AND my<68) THEN
  320.   selection%=2
  321.   WHILE MOUSE(0)<>0:WEND
  322.  END IF
  323.  IF (mx>20 AND mx<450) AND (my>74 AND my<94) THEN
  324.   selection%=3
  325.   WHILE MOUSE(0)<>0:WEND
  326.  END IF 
  327.  IF (mx>20 AND mx<450) AND (my>102 AND my<122) THEN
  328.   selection%=4
  329.   WHILE MOUSE(0)<>0:WEND
  330.  END IF 
  331.  IF (mx>20 AND mx<450) AND (my>130 AND my<150) THEN
  332.   selection%=5
  333.   WHILE MOUSE(0)<>0:WEND
  334.  END IF 
  335. WEND 
  336. WINDOW CLOSE 3
  337. END SUB
  338.  
  339. SUB introduction STATIC
  340. ' program introduction subroutine
  341. CLS
  342. PRINT
  343. PRINT TAB(4);"SIDEREAL is an interactive AmigaBasic program which can"
  344. PRINT TAB(4);"help us learn about time. We can explore the relationship"
  345. PRINT TAB(4);"between solar or civil time and sidereal time as well as"
  346. PRINT TAB(4);"the 'Julian Date' and calendar dates."
  347. PRINT
  348. PRINT TAB(4);"The Julian Date is the number of days that have passed"
  349. PRINT TAB(4);"since noon on January 1, 4713 B.C. It is an 'elapsed time'"
  350. PRINT TAB(4);"benchmark which is used in astronomy to predict the move-"
  351. PRINT TAB(4);"ment of celestial objects. The Julian Date also has a"
  352. PRINT TAB(4);"direct relationship with our calendar dates. For example,"
  353. PRINT TAB(4);"the number of days between two calendar dates is simply"
  354. PRINT TAB(4);"the difference between their Julian Dates."
  355. PRINT
  356. PRINT TAB(4);"The two most widely used calendars are the Julian and"
  357. PRINT TAB(4);"Gregorian calendars. The Julian calendar was used until"
  358. PRINT TAB(4);"October 4, 1582 and the Gregorian calendar (due to Pope
  359. PRINT TAB(4);"Gregory) went into effect on October 15, 1582."
  360. CALL newpage
  361. CLS
  362. PRINT
  363. PRINT TAB(4);"Solar or civil time is time measured relative to the sun"
  364. PRINT TAB(4);"while sidereal time is measured with respect to the stars."
  365. PRINT TAB(4);"Everyone and every star has a sidereal time. The sidereal"
  366. PRINT TAB(4);"time of a star or planet is called 'right ascension'. When"
  367. PRINT TAB(4);"your local sidereal time is equal to the right ascension"
  368. PRINT TAB(4);"of a celestial object, that object is aligned with your"
  369. PRINT TAB(4);"longitude position on the earth. This event is called a"
  370. PRINT TAB(4);"'meridian crossing'."
  371. PRINT
  372. PRINT TAB(4);"In this program both civil and sidereal time are input and"
  373. PRINT TAB(4);"output in hours, minutes and seconds. The calendar date is"
  374. PRINT TAB(4);"also input in numerical format. For example, May 1, 1984"
  375. PRINT TAB(4);"would be input as '5,1,1984'. Please note that B.C. dates"
  376. PRINT TAB(4);"are negative and A.D. dates are positive. Also, the first"
  377. PRINT TAB(4);"B.C. year is 0. When your longitude is requested, you"
  378. PRINT TAB(4);"should input this in degrees and minutes. This number is"
  379. PRINT TAB(4);"your west longitude on the earth."
  380. CALL newpage
  381. CLS
  382. PRINT
  383. PRINT TAB(4);"West longitude equals 360 - east longitude. For example,"
  384. PRINT TAB(4);"if you were at 85 degrees and 30 seconds east longitude,"
  385. PRINT TAB(4);"input '274,30' when prompted. Your time zone is an integer"
  386. PRINT TAB(4);"number between 0 and 23 and depends upon your location on"
  387. PRINT TAB(4);"the earth. For example, Eastern Standard Time is time zone"
  388. PRINT TAB(4);"number 5. You should also indicate if Daylight Savings"
  389. PRINT TAB(4);"Time is in effect at your location."
  390. CALL newpage
  391. END SUB
  392.  
  393. SUB newpage STATIC
  394. ' select next page subroutine
  395. PRINT
  396. PRINT TAB(13);"< press left mouse button to continue >"
  397. WHILE MOUSE(0)=0:WEND
  398. WHILE MOUSE(0)<>0:WEND
  399. END SUB
  400.      
  401.